#include <opencv2/opencv.hpp>

int main(int argc, char* argv[])
{
    using namespace std;
    using namespace cv;
    char ch, s[12];
    int cnt = (argc > 1 && stoi(argv[1])>0) ? stoi(argv[1]) : 0;
    VideoCapture cap(0);
    cap.set(cv::CAP_PROP_FRAME_WIDTH, 1280);
    cap.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
    cv::Mat frame;
    while (cap.isOpened()){
        if (!cap.read(frame)) {
            cv::destroyAllWindows();
            break;
        }
        cv::imshow("CameraTest", frame);
        ch = (char)cv::waitKey(10);
        if (ch == 'q')
            break;
        if (ch == 's') {
            sprintf(s, "test%d.png", cnt);
            cv::imwrite(s, frame);
            cnt++;
        }
    }
    return 0;
}
